﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;

public partial class Administrator_ServiceManager : System.Web.UI.Page
{
    DataProcess DataProcess = new DataProcess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {

            LoadData();

        
            
        }
    }

    public void LoadData()
    {


        CollectionPager1.DataSource = DataProcess.getAllAdv().DefaultView;
        CollectionPager1.PageSize = 12;
        CollectionPager1.BindToControl = rptData;
        rptData.DataSource = CollectionPager1.DataSourcePaged;
        rptData.DataBind();

    }
    public void searchData(string giatri)
    {


        CollectionPager1.DataSource = DataProcess.searchAdv(giatri).DefaultView;
        CollectionPager1.PageSize = 12;
        CollectionPager1.BindToControl = rptData;
        rptData.DataSource = CollectionPager1.DataSourcePaged;
        rptData.DataBind();

    }
    protected void btnAdnew1_Click(object sender, EventArgs e)
    {
        Response.Redirect("BannerAdd.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        DataProcess data = new DataProcess();
        try
        {

            string del_list = hdfCheck.Value;
            string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < sp_list.Length; i++)
            {
                int a = int.Parse(sp_list[i]);

                if (data.delAdv(a))
                {

                    divMessage.InnerHtml = O2S_Message.Success("System", "SuccessFully");


                }
            }
            LoadData();
        }
        catch (Exception ex)
        {

            divMessage.InnerHtml = O2S_Message.Error("System", "Error! " + ex.Message);
        }
    }
    protected void btnsearch_Click(object sender, EventArgs e)
    {
        string txtsearch = ddlsearch.Text;

        
        if ("Quảng cáo giữa trang".Equals(txtsearch)) {

            searchData("advleft");
            
        }
        if ("Quảng cáo phải".Equals(txtsearch)) {

            searchData("advright");
        
        }
        if ("Quảng cáo ngân hàng".Equals(txtsearch))
        {

            searchData("advbottom");

        }
        if ("All".Equals(txtsearch))
        {

            LoadData();

        }

    }
    protected void btnUpdateDisplayOrder_Click(object sender, EventArgs e)
    {  
            LoadData();
    }
}